package cn.stylefeng.guns.modular.app.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.app.entity.MovingPalletsmerge;
import cn.stylefeng.guns.modular.app.mapper.MovingPalletsmergeMapper;
import cn.stylefeng.guns.modular.app.model.params.MovingPalletsmergeParam;
import cn.stylefeng.guns.modular.app.model.result.MovingPalletsmergeResult;
import  cn.stylefeng.guns.modular.app.service.MovingPalletsmergeService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 移库和托 服务实现类
 */
@Service
public class MovingPalletsmergeServiceImpl extends ServiceImpl<MovingPalletsmergeMapper, MovingPalletsmerge> implements MovingPalletsmergeService {

    @Override
    public void add(MovingPalletsmergeParam param){
        MovingPalletsmerge entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(MovingPalletsmergeParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(MovingPalletsmergeParam param){
        MovingPalletsmerge oldEntity = getOldEntity(param);
        MovingPalletsmerge newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public MovingPalletsmergeResult findBySpec(MovingPalletsmergeParam param){
        return null;
    }

    @Override
    public List<MovingPalletsmergeResult> findListBySpec(MovingPalletsmergeParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(MovingPalletsmergeParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(MovingPalletsmergeParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private MovingPalletsmerge getOldEntity(MovingPalletsmergeParam param) {
        return this.getById(getKey(param));
    }

    private MovingPalletsmerge getEntity(MovingPalletsmergeParam param) {
        MovingPalletsmerge entity = new MovingPalletsmerge();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
